<template>
     <div class="exam index">
         <Header></Header>
         <div class="main2">
            <p class='current-nav'>当前位置 : <router-link to='index'>首页</router-link> <i> > </i>
                <router-link to='assessed'>{{varname}}应急预案评审</router-link> <i> > </i>个人评审意见表
            </p>

            <div class="infor search">
                <div class="form-container clearfix">
                <div class="left-box">
                    <p v-if="tit.length > 0" style="color:#4080ff;line-height:680px;text-align:center;font-size:14px;">{{tit}}</p> 
                    <iframe v-else :src="leftImg"
                            frameborder="0"
                            scrolling="no"
                            width="100%"
                            height="100%"></iframe>
                
                </div>
                <div class="right-box">
                    <div class='bts-group'>
                    <el-button v-for='(item,index) in uploadType'
                                :key='index'
                                @click='goPath(item.path)'
                                :class='activeIndex2==index ? "sure":""'>{{item.name}}</el-button>
                    </div>
                    <h3 class="table-name"> 应急预案个人评审意见表</h3>
                    <table border='1'  v-if='data.length>0'>
                    <tr>
                        <td>{{data[0].reviewItemOne}}</td>
                        <td>{{varname}}</td>
                    </tr>
                    <tr>
                        <td style="width:150px;">{{data[1].reviewItemOne}}</td>
                        <td>
                        </td>
                    </tr>
                    <tr class="suggest">
                        <td style="border-bottom:0;border-right:0;"><span class='span-top'>{{data[2].reviewItemOne}} </span> </td>
                        <td>
                        
                        <el-input type="textarea"
                                    v-model="suggest"></el-input>
                        </td>
                    </tr>
                    <tr class="sign-word">
                        <td style="border-top:0;border-right:0;"> 评审专家(签字) :</td>
                        <td   class="sign-word">
                            <img :src="signImg" alt="" >    
                        </td>
                    </tr>
                    <tr>
                        <td>备注</td>
                        <td>
                        <el-input type="textarea"
                                    v-model="remark"></el-input>
                        </td>
                    </tr>
                    </table>
                    <div class="bts">
                    <el-button class='sure' @click="saveData(0)">保存</el-button>
                        <el-button class='sure' @click="startSend" v-if="flag">{{identity=='1' ? '评审意见汇总' :'发送组长'}}</el-button>
                        <el-button class='sure' v-else >{{identity=='1' ? '评审意见汇总' :'发送组长'}}</el-button>
                    </div>
                </div>
                </div>
            </div>
         </div>
         <Footer></Footer>
    </div>
</template>

<script>
import Header from '../common/header2'
import Footer from '../common/footer'
import config from '../../config.js'
import { setTimeout } from 'timers';
export default {
  components: {
    Header,
    Footer
  },
  data () {
    return {
      data:[],
      varname:'',
      varCompanyName:'',
      remark: '',
      identity:'',
      leftImg:'',
      tit:"",
      signImg:'',
      suggest:'',
      flag:true,
      time: null,
      name: '',
      planSummaryId:'',
      reviewTemplateName:'',
      uploadType: [
        {
          name: '形式评审',
          path: 'situationexam'
        },
        {
          name: '要素评审',
          path: 'keyexam'
        },
        {
          name: '附件要素评审',
          path: 'powerexam'
        },
        {
          name: '个人评审意见',
          path: 'personexam'
        }
      ],
      activeIndex2: 3,
      autograph:''

    };
  },
  mounted(){
    this.varname = localStorage.planname.split('.')[0]
    this.getData()
    this.getLeftUrl()
      this.signImg = localStorage.signImg
      this.autograph = localStorage.autograph
      this.identity = localStorage.identity
  },
  methods:{
    goPath(path){
      this.saveData(0,path)
    },
    lookstatus(item){
          let  baseUrl = item.viewUrl;
          var urlpath = baseUrl.indexOf("?") + 1;
          urlpath = baseUrl.substring(urlpath);
          var arrapi = urlpath.split("&");
          let  uesrMessage = {}
          arrapi.forEach(
              (item)=>{
                  var brrapi = [];
                  brrapi = item.split("=");
                  uesrMessage[brrapi[0]] = brrapi[1];
              }
          )

          let id = uesrMessage.srcFid;
          let  expires = Date.parse(new Date());
          let a = "FastDFS1234Bossien"+id +expires
          let token = this.$md5(a)
          token = token.toUpperCase()
          let that = this;
          $.ajax({
              url:config.baseUrl3+"queryPublishFileInfo.do?appId=001&srcFid="+id+"&expires="+expires+"&token="+token,
              type:'GET', //GET
              async:false,    //或false,是否异步
              data:{
              },
              timeout:5000,    //超时时间
              success:function(data,textStatus,jqXHR){
                let status = JSON.parse(data);
                if(!status.success){
                  that.tit =  "文件正在转码中..."
                  
                }
                if(status.dataObj.srcFileStatusName=="12"){
                    that.leftImg = item.viewUrl
                }else{
                  that.tit =  "文件正在转码中..."
                }
              },
              error:function(xhr,textStatus){
              },
              complete:function(){
              }
          })
      },
     getLeftUrl(){
      this.postData(1)
          .then(res => {
            if (res.data.meta.success) {
             this.lookstatus(res.data.data)
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
    },
  saveData(n,path){

if( this.suggest=='' ){

this.$message.warning('专家建议不能为空')
}else{
 this.postData(2,4,[], this.autograph,this.suggest ,this.remark)
          .then(res => {
            if (res.data.meta.success) {
              if(n==0){
   this.$message.success(res.data.meta.message)
                 if(path){
                   this.$router.push(path)
                 }
              }else{
                  this.sendData()
              }
           
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
}
  },
  startSend(){
    
if( this.suggest=='' ){

this.$message.warning('专家建议不能为空')
}else{
    this.flag=false
    var t = 10;
     this.time = setInterval(() => {
          t--;
          if (t != 0) {
           
          } else {
            t = 0;
            clearInterval(this.time);
            this.flag = true;
          }
        }, 1000);
    this.saveData(1)  
}
      
  },
 sendData(){
   let url = config.baseUrl +'emergency/v1.0/review/send'
      this.$axios
          .post(url, {
             planSummaryId: localStorage.planid,
               userId:localStorage.userid
          })
          .then(res => {
            if (res.data.meta.success) {
              var msg = '发送成功'
              if(localStorage.identity==1){
                msg='发送成功,请在已评审模块进行意见汇总'
              }
              this.$message.success(msg)
              setTimeout(()=>{
                  this.$router.push('assessed')
              },1000)
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
    },
     getData(){
       this.postData(0,4)
        .then( res=> {
            if (res.data.meta.success) {
               this.data = res.data.data.list
                 this.varCompanyName = res.data.data.companyName
               res.data.data.list.map((item)=>{
                
                  if(item.opinion){
this.suggest = item.opinion
                 }
                  if(item.remarks){
 this.remark=item.remarks
                 }
               })
            } else {
               this.$message.warning(res.data.meta.message)
            }
        })
        .catch(function (res) {
           console.log(res)
        })
    },
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='less'>
@import "../../../static/css/information.less";
.exam {
  .search {
    .form-container {
      padding: 0 0 70px;
      margin: 0 auto;
      .bts-group {
        width: 510px;
        margin: 0 auto 30px;
        .el-button {
          width: 120px;
          color: #3f80fe;
          border-radius: 8px;
          border: 1px solid #3f80fe;
        }
        .sure {
          color: #fff;
          background: #4080ff;
         /* background: linear-gradient(90deg, #6eb1ff 20%, #3372ff 80%);*/
        }
      }
      .bts {
        text-align: center;
        width: 100%;
        .el-button {
          float: none;
        }
        .sure {
          color: #fff;
          background: #4080ff;
        /*  background: linear-gradient(90deg, #6eb1ff 20%, #3372ff 80%);*/
        }
      }
      .suggest {
        td {
          position: relative;
        }
        .span-top {
          position: absolute;
          top: 0;
          left: 20px;
        }
        td:frist-child {
          border-right: 0;
          border-bottom: 0;
        }
        td:last-child {
          border-left: 0;
          border-bottom: 0;
          padding-top: 5px;
        }
      }
      .sign-word {
        td:frist-child {
          border-right: 0;
          border-top: 0;
        }
        td:last-child {
          border-left: 0;
          border-top: 0;
          text-align: center;
        }
      }
      .el-textarea__inner {
        resize: none;
        border: 0;
        height: 200px;
        cursor: pointer;
      }
      .el-input__inner {
        border: 0;
        cursor: pointer;
      }
      .detail-btn {
        border: 0;
        color: #4180ff;
        background: #f7f6fe;
        border-radius: 8px;
      }
    }
  }
}
</style>
